package com.yuanthink.gwt.client.tools;

import java.util.Date;

import com.google.gwt.i18n.client.DateTimeFormat;

/**
 * 日期处理工具类
 * @author 06peng
 * 
 */
public class DateUtil {
	// cn type
	public static final String FORMAT_LONGDATETIME = "yyyy-MM-dd HH:mm:ss";
	public static final String FORMAT_SHORTDATETIME = "yyyy-MM-dd";
	public static final String FORMAT_LONGDATETIME_COMPACT = "yyyyMMddHHmmss";
	public static final String FORMAT_SHORTDATETIME_COMPACT = "yyyyMMdd";

	// en type
	public static final String FORMAT_LONGDATETIME_EN = "MM-dd-yyyy HH:mm:ss a";
	public static final String FORMAT_SHORTDATETIME_EN = "MM-dd-yyyy";

	private DateUtil() {
	}

	/**
	 * 返回yyyy-MM-dd HH:mm:ss格式的长日期时间字符串
	 */
	public static String getLongDate(Date argDate, String curLang)
			throws Exception {
		if (curLang.equals("en")) {
			return DateTimeFormat.getFormat(FORMAT_LONGDATETIME_EN).format(
					argDate);
		} else {
			return DateTimeFormat.getFormat(FORMAT_LONGDATETIME)
					.format(argDate);
		}
	}

	/**
	 * 返回yyyy-MM-dd格式的长日期时间字符串
	 */
	public static String getShortDate(Date argDate, String curLang)
			throws Exception {
		if (curLang.equals("en")) {
			return DateTimeFormat.getFormat(FORMAT_SHORTDATETIME_EN).format(
					argDate);
		} else {
			return DateTimeFormat.getFormat(FORMAT_SHORTDATETIME).format(
					argDate);
		}
	}

	public static String getFormatDate(Date argDate, String curLang,
			String format_cn, String format_en) throws Exception {
		if (curLang.equals("en")) {
			return DateTimeFormat.getFormat(format_en).format(argDate);
		} else {
			return DateTimeFormat.getFormat(format_cn).format(argDate);
		}
	}
}